package com.ruoyi.manager.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manager.domain.TbeduExercise;
import com.ruoyi.manager.service.ITbeduExerciseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 作业发布Controller
 * 
 * @author 罗
 * @date 2021-09-17
 */
@Controller
@RequestMapping("/manager/exercise")
public class TbeduExerciseController extends BaseController
{
    private String prefix = "manager/exercise";

    @Autowired
    private ITbeduExerciseService tbeduExerciseService;

    @RequiresPermissions("manager:exercise:view")
    @GetMapping()
    public String exercise()
    {
        return prefix + "/exercise";
    }

    /**
     * 查询作业发布列表
     */
    @RequiresPermissions("manager:exercise:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbeduExercise tbeduExercise)
    {
        startPage();
        List<TbeduExercise> list = tbeduExerciseService.selectTbeduExerciseList(tbeduExercise);
        return getDataTable(list);
    }

    /**
     * 导出作业发布列表
     */
    @RequiresPermissions("manager:exercise:export")
    @Log(title = "作业发布", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbeduExercise tbeduExercise)
    {
        List<TbeduExercise> list = tbeduExerciseService.selectTbeduExerciseList(tbeduExercise);
        ExcelUtil<TbeduExercise> util = new ExcelUtil<TbeduExercise>(TbeduExercise.class);
        return util.exportExcel(list, "作业发布数据");
    }

    /**
     * 新增作业发布
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存作业发布
     */
    @RequiresPermissions("manager:exercise:add")
    @Log(title = "作业发布", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbeduExercise tbeduExercise)
    {
        return toAjax(tbeduExerciseService.insertTbeduExercise(tbeduExercise));
    }

    /**
     * 修改作业发布
     */
    @GetMapping("/edit/{fTaskid}")
    public String edit(@PathVariable("fTaskid") Long fTaskid, ModelMap mmap)
    {
        TbeduExercise tbeduExercise = tbeduExerciseService.selectTbeduExerciseByFTaskid(fTaskid);
        mmap.put("tbeduExercise", tbeduExercise);
        return prefix + "/edit";
    }

    /**
     * 修改保存作业发布
     */
    @RequiresPermissions("manager:exercise:edit")
    @Log(title = "作业发布", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbeduExercise tbeduExercise)
    {
        return toAjax(tbeduExerciseService.updateTbeduExercise(tbeduExercise));
    }

    /**
     * 删除作业发布
     */
    @RequiresPermissions("manager:exercise:remove")
    @Log(title = "作业发布", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbeduExerciseService.deleteTbeduExerciseByFTaskids(ids));
    }
}
